package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.*;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BasecategoryController {
    @Autowired
    private BaseCategoryService baseCategoryService;
    @Autowired
    private BaseAttrInfoService baseAttrInfoService;
    @GetMapping("getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> baseCategory1=baseCategoryService.getCategory1();
        return Result.ok(baseCategory1);
    }
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id") Long category1Id){
        List<BaseCategory2> baseCategory2=baseCategoryService.getCategory2(category1Id);
        return Result.ok(baseCategory2);
    }
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id") Long category2Id){
        List<BaseCategory3> baseCategory3=baseCategoryService.getCategory3(category2Id);
        return Result.ok(baseCategory3);
    }
    /*
    * 根据id查找平台属性
    * */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable( value = "category1Id",required = false) Long category1Id, @PathVariable(value = "category2Id",required = false) Long category2Id, @PathVariable(value = "category3Id",required = false) Long category3Id){
       List<BaseAttrInfo> baseAttrInfoList= baseAttrInfoService.attrInfoList(category1Id, category2Id, category3Id);
       return Result.ok(baseAttrInfoList);
    }
    /**
     * 保存和修改

    * */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo)
    {
        baseAttrInfoService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }
    /*
    * 根据平台属性id 查询凭条属性值
    * */
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable(value = "attrId") Long attrId){
    List<BaseAttrValue> baseAttrValueList=   baseAttrInfoService.getAttrValueList(attrId);
    return Result.ok(baseAttrValueList);
    }

}
